package com.clouds.wms.util;

import javax.servlet.http.HttpServletRequest;

public class RequestHelper {
	
	/**
	 * 获取request中的int类型参数,如果不存在或错误返回default参数
	 * @param request
	 * @param paraname
	 * @param defaultVal
	 * @return
	 */
	public static int getInt(HttpServletRequest request, String paraname, int defaultVal) {
		try {
			return Integer.parseInt(request.getParameter(paraname));
		} catch (Exception e) {
			return defaultVal;
		}
	}
	
	/**
	 * 获取request中的double类型参数,如果不存在或错误返回default参数
	 * @param request  
	 * @param paraname 
	 * @param defaultVal
	 * @return
	 */
	public static double getDouble(HttpServletRequest request,String paraname,double defaultVal){
		try{
			return Double.parseDouble(request.getParameter(paraname));
		}catch(Exception e){
			return defaultVal;
		}
	}
	
	/**
	 * 获取request中的long类型参数,如果不存在或错误返回default参数
	 * @param request
	 * @param paraname
	 * @param defaultVal
	 * @return
	 */
	public static long getLong(HttpServletRequest request, String paraname,int defaultVal) {
		try {
			return Long.parseLong(request.getParameter(paraname));
		} catch (Exception e) {
			return defaultVal;
		}
	}

	/**
	 * 获取request中的字符串类
	 * @param request
	 * @param paraname
	 * @return
	 */
	public static String getString(HttpServletRequest request, String paraname) {
		return request.getParameter(paraname) == null ? "" : request.getParameter(paraname);
	}

}
